package com.example.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

class Employee {
    private String name;
    private int age;
    private String position;

    public Employee(String name, int age, String position) {
        this.name = name;
        this.age = age;
        this.position = position;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getPosition() {
        return position;
    }

    @Override
    public String toString() {
        return "Name: " + name + ", Age: " + age + ", Position: " + position;
    }
}

class Main {
    public static void main(String[] args) {
        Employee[] employees = new Employee[20];
        getEmp(employees);
        List<Employee> list = new ArrayList<>(employees.length);
        for (Employee employee : employees) {
            list.add(employee);
        }
        //test1(list);
        //test2(list);
        //test3(list);
        //test4();
        test7();
    }
    //排序
    private static void test7() {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
        numbers.stream().skip(2).forEach(System.out::println);
    }

    //排序
    private static void test6() {
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Eve");
        names.stream().sorted(Comparator.reverseOrder()).forEach(System.out::println);
    }

    //排序
    private static void test5() {
        List<Integer> numbers = Arrays.asList(5, 2, 8, 1, 3);
        numbers.stream().sorted().forEach(System.out::println);
    }

    private static void test4() {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 2, 4, 3, 5, 4, 5);
        numbers.stream().distinct().collect(Collectors.toList())
                .forEach(System.out::println);
    }

    private static void test3(List<Employee> list) {
        list.stream().map(employee -> employee.getName().toUpperCase()).collect(Collectors.toList())
                .forEach(System.out::println);
    }

    private static void test2(List<Employee> list) {
        list.stream().filter(employee -> employee.getAge()>=30).collect(Collectors.toList())
                .forEach(System.out::println);
    }

    private static void test1(List<Employee> list) {
        //foreach
        list.forEach(System.out::println);
    }

    private static void getEmp(Employee[] employees) {
        employees[0] = new Employee("John", 30, "Manager");
        employees[1] = new Employee("Emma", 25, "Engineer");
        employees[2] = new Employee("Michael", 35, "Analyst");
        employees[3] = new Employee("Sophia", 28, "Assistant");
        employees[4] = new Employee("William", 32, "Designer");
        employees[5] = new Employee("Olivia", 29, "Manager");
        employees[6] = new Employee("James", 31, "Engineer");
        employees[7] = new Employee("Ava", 27, "Analyst");
        employees[8] = new Employee("Benjamin", 33, "Assistant");
        employees[9] = new Employee("Isabella", 26, "Designer");
        employees[10] = new Employee("Mason", 34, "Manager");
        employees[11] = new Employee("Mia", 28, "Engineer");
        employees[12] = new Employee("Liam", 35, "Analyst");
        employees[13] = new Employee("Harper", 30, "Assistant");
        employees[14] = new Employee("Jacob", 29, "Designer");
        employees[15] = new Employee("Evelyn", 32, "Manager");
        employees[16] = new Employee("Ethan", 31, "Engineer");
        employees[17] = new Employee("Amelia", 27, "Analyst");
        employees[18] = new Employee("Alexander", 33, "Assistant");
        employees[19] = new Employee("Charlotte", 26, "Designer");
    }
}